import 'package:FineArt/constants.dart';
import 'package:FineArt/core/widget/list/notice_item.dart';
import 'package:FineArt/utils/log_util.dart';
import 'package:FineArt/utils/size_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:FineArt/core/api/class_api.dart';
//创建班级
class CreateClassPage extends StatefulWidget {
  TeacherClassesEntity classesEntity;
  CreateClassPage({this.classesEntity});
  @override
  State<StatefulWidget> createState() {
    return _CreateClassPageState();
  }
}

class _CreateClassPageState extends State<CreateClassPage> {
  String title = "班级XX";
  bool isAdd=true;
  @override
  void initState() {
    super.initState();
    isAdd=widget.classesEntity==null?true:false;
  }

  final myController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    if(!isAdd){
      myController.text = widget.classesEntity.className;
    }

    return Scaffold(
      appBar: AppBar(
        shadowColor: Colors.grey.shade100,
        title: Text(
          isAdd?"添加":"修改",
          style: TextStyle(color: text_black, fontSize: setSp(18)),
        ),
        centerTitle: true,
        elevation: 0.5,
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        toolbarHeight: getPortraitSHeight(40),
        leading: IconButton(
            alignment: Alignment.centerLeft,
            icon: Image.asset(
              "assets/images/icon_back_black.png",
              width: getPortraitSWidth(11),
              height: getPortraitSHeight(18),
            ),
            onPressed: () {
              Navigator.of(context).pop();
            }),
        actions: [getAppBarRightActionItem()],
      ),
      body: SafeArea(
        child: Container(
            margin: EdgeInsets.symmetric(horizontal: 10),
            color: Colors.white,
            child: Row(
              children: [
                Expanded(
                    child: TextField(
                  decoration: InputDecoration(
                      helperText: "请输入班级名称",
                      border: InputBorder.none,
                      isDense: true,
                      fillColor: Colors.white,
                      contentPadding: const EdgeInsets.symmetric(vertical: 10.0),
                      helperStyle: TextStyle(
                          color: textfield_help_black, fontSize: setSp(12))),
                  controller: myController,
                  onChanged: (v) {
                    LogUtil.d("onchange $v  ${myController.text}");
                  },
                )),
                IconButton(
                    icon: Image.asset(
                      "assets/images/icon_clear_input.png",
                      width: getPortraitSWidth(18.5),
                      height: getPortraitSHeight(18.5),
                    ),
                    onPressed: () {
                      myController.clear();
                    }),
              ],
            )),
      ),
    );
  }

  Widget getAppBarRightActionItem() {
    return InkWell(
      child: Padding(
          padding: EdgeInsets.only(top: getPortraitSHeight(10), right: 10),
          child: Text(
            "确定",
            style: TextStyle(fontSize: setSp(16), color: text_black),
          )),
      onTap: () {
        LogUtil.d("create click>>>>>>>>>>>>>>>>>>>>");
        setState(() {

        });
      },
    );
  }
}
